﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Htss.Platform.Data;

namespace DreamBox.DAL.Posts
{
    public class PostsClass
    {
        /// <summary>
        /// 判断一个用户是否有阅读该类下文章的权限
        /// </summary>
        /// <param name="GID"></param>
        /// <param name="PostsID"></param>
        /// <returns></returns>
        public bool IsRead(int GID, int PostsID)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select ID from dbox_PostsClassCompetence where ");
            sb.Append(" CID=(select isnull(CID,0) from dbox_Posts where PostsID=" + PostsID + ")");
            sb.Append(" and GID=" + GID + " and IsRead=1");

            DbAction db = new DbAction();
            if (db.Select(sb.ToString(), true).Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 判断一个用户是否有回复该类下文章的权限
        /// </summary>
        /// <param name="GID"></param>
        /// <param name="PostsID"></param>
        /// <returns></returns>
        public bool IsReply(int GID,int PostsID)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select ID from dbox_PostsClassCompetence where ");
            sb.Append(" CID=(select isnull(CID,0) from dbox_Posts where PostsID="+PostsID+")");
            sb.Append(" and GID="+GID+" and IsReply=1");

            DbAction db = new DbAction();
            if (db.Select(sb.ToString(), true).Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public DataTable GetClass(int GID)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select pc.CID,pc.ClassName from dbox_PostsClass as pc inner join ");
            sb.Append(" dbox_PostsClassCompetence as pcc on pc.CID=pcc.CID ");
            sb.Append(" where pc.IsStatus=1 and pcc.GID="+GID+" and IsPosts=1");

            DbAction db = new DbAction();
            return db.Select(sb.ToString(), true);
        }
    }
}
